home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / palis.lha / Palis / src / PALIS.h < prev    next >
C/C++ Source or Header  |  1992-09-02  |  5KB  |  146 lines

  1. /*
  2.     ·C·O·D·E·X· ·D·E·S·I·G·N· ·S·O·F·T·W·A·R·E·
  3.     presents
  4.  
  5.     PatchLibraries Utility PALIS V1.00
  6.  
  7.     FILE:    PALIS.h
  8.     TASK:    include for programms that want to read some
  9.             data from PALIS
  10.     NOTE:    TabLen=3
  11.  
  12.      You may don't like ViewPALIS (included in the archive)
  13.     or want to know some special information about patches tracked
  14.     by PALIS.
  15.      Here's the description of how these information are tracked
  16.     and how to access them.
  17.  
  18.     (c)1995 by Hans Bühler, codex@stern.mathematik.hu-berlin.de
  19.     Attention ! This is the actual e-mail address !
  20.     h0348kil... is obsolete !
  21. */
  22.  
  23. #include    <exec/exec.h>
  24.  
  25. // ---------------------------
  26. // PALIS patches tracking
  27. // ---------------------------
  28.  
  29. /***************************************************
  30.  * All information about patches tracked by PALIS    *
  31.  * might be received using "struct plBase" (see        *
  32.  * below)                                                        *
  33.  * If you want to access PALIS plBase (see below)    *
  34.  * do the following:                                            *
  35.  ***************************************************
  36.  *
  37.  *    FIRST: WAIT UNTIL PLBASE IS READY FOR YOU
  38.  *    -----------------------------------------
  39.  *
  40.  *    struct plBase *ObtainPalisBase(void)
  41.  *    {
  42.  *        struct plBase    *plBase;
  43.  *
  44.  *        if(plBase = (struct plBase *)FindSemaphore(PALIS_SEMAPHORE_NAME))
  45.  *            ObtainSemaphoreShared(&plBase->Sem);
  46.  *
  47.  *        return plBase;
  48.  *    };
  49.  *
  50.  *    SECOND: FIND BASE AND CHECK WHETHER YOU MAY ACCESS IT
  51.  *    -----------------------------------------------------
  52.  *    
  53.  *    struct plBase *AttemptPalisBase(void)
  54.  *    {
  55.  *        struct plBase    *plBase;
  56.  *
  57.  *        if(plBase = (struct plBase *)FindSemaphore(PALIS_SEMAPHORE_NAME))
  58.  *            if(!AttemptSemaphoreShared(&plBase->Sem))
  59.  *                plBase    =    0;
  60.  *
  61.  *        return plBase;
  62.  *    };
  63.  *
  64.  *    THIRD: RELEASE BASE IF YOU FINISHED WORK
  65.  *    ----------------------------------------
  66.  *    
  67.  *    void ReleasePLBase(struct plBase *plBase)
  68.  *    {
  69.  *        if(plBase)
  70.  *            ReleaseSemaphore(&plBase->Sem);
  71.  *    }
  72.  *
  73.  ***************************************************
  74.  * Please remember these points:                            *
  75.  * 1) ALL DATA ARE READ-ONLY !!!!!!!!!!!!!!!!        *
  76.  * 2) Please release plBase as soon as possible        *
  77.  *        since PALIS will block all other programms    *
  78.  *        trying to patch _any_ library !!                    *
  79.  ***************************************************/
  80.  
  81. #define    PALIS_SEMAPHORE_NAME        "PALIS_patch_list"        // don't use FindSemaphore(PL...); it could be removed between
  82.                                                                             // Find..() and Obtain..() !!!!!
  83. #define    PALIS_VERSION                0x100                            // check this...
  84. #define    PALIS_NAME                    "PALIS V1.00"                // if you want to refer to PALIS' name ;^)
  85.  
  86. /***************************************************************************
  87.  * these structs are the basic structures used to track each SetFunction()    *
  88.  * call !!!                                                                                        *
  89.  * they may not behave strange but note that semaphore locking is used for    *
  90.  * the whole heap using plBase->Sem !!!!!!!!!                                        *
  91.  ***************************************************************************/
  92.  
  93. struct plPatch                /* patches an einem offset */
  94.     {
  95.         struct MinNode        Node;                            // tracking...
  96.         char                    *ProcName;                    // _copy_ of processname or CLI command name
  97.                                                                 // might be an error message if you ran out of
  98.                                                                 // memory while allocating mem for name...
  99.         APTR                    plOffset;                    // struct plOffset *
  100.  
  101.         UWORD                    _Cookie_;                    // set to ASS-JMP, address of this entry is send to SetFunction()
  102.         APTR                    PatchFunc,                    // newly set function
  103.                                 OldFunc;                        // address of func having been replaced (mostly last &plPatch->_Cookie_..)
  104.                                                                 // 0 => patch isn't active anymore
  105.                                                                 // (part of list because other patches will jump here)
  106.     };
  107. #define    PL_ACTIVE(PAT)    ((PAT)->OldFunc)            // use this to detect whether a patch has been removed..
  108.  
  109. struct plOffset            /* offsets in einer lib, die gepatched wurden */
  110.     {
  111.         struct MinNode        Node;                            // tracking...
  112.         WORD                    Offset;                        // offset which has been patched
  113.         APTR                    plLib;                        // struct plLib *
  114.  
  115.         APTR                    OriginalFunc;                // original function...
  116.  
  117.         struct MinList        PatchList;                    // list of patches (struct plPatch *)
  118.         UWORD                    PatchCnt;                    // counter
  119.     };
  120.  
  121. struct plLib                /* libraries, die gepatched wurden */
  122.     {
  123.         struct MinNode        Node;                            // tracking... (ln_Name points to lib...)
  124.         struct Library        *Lib;                            // ID: OpenLib() ... close if cnt == 0 !
  125.  
  126.         struct MinList        OffList;                        // list of offsets patched (struct plOffset *)
  127.         UWORD                    OffCnt;                        // counter
  128.     };
  129.  
  130. struct plBase                /* basic struct mit sigSemaphore */
  131.     {
  132.         struct SignalSemaphore    Sem;                    // avoid Forbid()/Permit() use !!!
  133.                                                                 // use FindSemaphore() to find this Base somewhere... ;^)
  134.         UWORD                            Version;                // Version of PALIS (PALIS_VERSION)
  135.  
  136.         struct MinList                LibList;                // list of libs having been patched (struct plLib *)
  137.         UWORD                            LibCnt;                // counter
  138.  
  139.         LONG                            PatchCnt;            // just a counter... total number of patches
  140.                                                                 // this is reliable...
  141.  
  142.         BOOL                            LowMemErr;            // if TRUE, a memory allocation error
  143.                                                                 // has been detected during any new patch.
  144.                                                                 // => no more PALIS work !!!!!
  145.     };
  146.